import  Vue from  'vue'
import VueRouter from 'vue-router'
import login from "@/views/login";
import index from "@/views/index";
import Repair from "@/components/Repair";
import User from "@/components/User";
import UserManager from "@/components/UserManager";
import MenuManager from "@/components/MenuManager";
import RoomManager from "@/components/RoomManager";
import MyRoom from "@/components/MyRoom";
import ReviewRepair from "@/components/ReviewRepair";
import Complaints from "@/components/Complaints";
import RepairManager from "@/components/RepairManager";
import ComplaintsManager from "@/components/ComplaintsManager";
import ParkingSpaceManager from "@/components/ParkingSpaceManager";
import NoticeManager from "@/components/noticeManager";
import Notice from "@/components/Notice"
import LicenseManager from "@/components/LicenseManager";

Vue.use(VueRouter)

const routes=[
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: login
    },
    {
        name: 'index',
        path: '/index',
        component: index,
        children:[
            {
                path: '',
                name: '',
            },
            {
                path: 'licenseManager',
                name: 'licenseManager',
                component:LicenseManager
            },



            {
                path: 'reviewRepair',
                name: 'reviewRepair',
                component:ReviewRepair
            },
            {
                path: 'notice',
                name: 'notice',
                component:Notice
            },
            {
                path: 'noticeManager',
                name: 'noticeManager',
                component:NoticeManager
            },
            {
                path: 'parkingSpaceManager',
                name: 'parkingSpaceManager',
                component:ParkingSpaceManager
            },

            {
                path: 'user',
                name: 'user',
                component:User
            },
            {
                path: 'userManager',
                name: 'userManager',
                component:UserManager
            },
            {
                path: 'menuManager',
                name: 'menuManager',
                component:MenuManager
            },
            {
                path: 'roomManager',
                name: 'roomManager',
                component:RoomManager
            },
            {
                path: 'myRoom',
                name: 'myRoom',
                component:MyRoom
            },
            {
                path: 'repair',
                name: 'repair',
                component:Repair
            },
            {
                path: 'complaints',
                name: 'complaints',
                component:Complaints
            },
            {
                path: 'complaintsManager',
                name: 'complaintsManager',
                component:ComplaintsManager
            },
            {
                path: 'repairManager',
                name: 'repairManager',
                component:RepairManager
            },

        ]
    }
]

const  router=new VueRouter({
    routes
})

router.beforeEach((to,from,next)=>{
    next();
    if (to.path==='/login'){
        next();
    }else {
        let Token=localStorage.getItem("Token")
        if (Token ===null || Token===''){
            next('/login')
            console.log("没有token，跳转到登录页面")
        }else {
            next();
        }
    }

})

export default router
